package com.healthy.reminders.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.reminders.domain.HealthReminders;
import com.healthy.reminders.service.IHealthRemindersService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 定时提醒Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/HealthReminders")
public class HealthRemindersController extends BaseController
{
    @Autowired
    private IHealthRemindersService healthRemindersService;

    /**
     * 查询定时提醒列表
     */
    @RequiresPermissions("reminders:HealthReminders:list")
    @GetMapping("/list")
    public TableDataInfo list(HealthReminders healthReminders)
    {
        startPage();
        List<HealthReminders> list = healthRemindersService.selectHealthRemindersList(healthReminders);
        return getDataTable(list);
    }

    /**
     * 导出定时提醒列表
     */
    @RequiresPermissions("reminders:HealthReminders:export")
    @Log(title = "定时提醒", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthReminders healthReminders)
    {
        List<HealthReminders> list = healthRemindersService.selectHealthRemindersList(healthReminders);
        ExcelUtil<HealthReminders> util = new ExcelUtil<HealthReminders>(HealthReminders.class);
        util.exportExcel(response, list, "定时提醒数据");
    }

    /**
     * 获取定时提醒详细信息
     */
    @RequiresPermissions("reminders:HealthReminders:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(healthRemindersService.selectHealthRemindersById(id));
    }

    /**
     * 新增定时提醒
     */
    @RequiresPermissions("reminders:HealthReminders:add")
    @Log(title = "定时提醒", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthReminders healthReminders)
    {
        return toAjax(healthRemindersService.insertHealthReminders(healthReminders));
    }

    /**
     * 修改定时提醒
     */
    @RequiresPermissions("reminders:HealthReminders:edit")
    @Log(title = "定时提醒", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthReminders healthReminders)
    {
        return toAjax(healthRemindersService.updateHealthReminders(healthReminders));
    }

    /**
     * 删除定时提醒
     */
    @RequiresPermissions("reminders:HealthReminders:remove")
    @Log(title = "定时提醒", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthRemindersService.deleteHealthRemindersByIds(ids));
    }
}
